<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
	    //$title=M('Config')->order('id desc')->getfield('title');
	    $title=M('Config')->getfield('title');
	    $username=M('User')->getfield('username');
	    $time=M('User')->order('id desc')->getfield('time');
	    $content=M('Content')->order('id desc')->select();
	    //$archives=M('Content')->getfield('archives');
	    //p($archives);
	    $this->assign('title',$title);
	    $this->assign('username',$username);
	    $this->assign('time',$time);
	    $this->assign('c_title',$c_title);
	    $this->assign('content',$content);
	    $this->assign('archives',$archives);
	    $this->display();
    }

    public function insert(){

	    $this->display();

	    }

    public function insertd(){

	    //$data['title']=I('title');
	    //$data['content']=I('content');
	    if(!IS_POST){$this->error('error');}
	    $data=I();
	    $data['time']=date('Y-m-d');
	    //p($data);die;

	    $User = M('Content');
	    //$User->create($data);
	    if($User->add($data)) {

		    $this->success('成功','index');
	    }

	    else
	    {
		    $this->error('失败');

	    }
 
	     
    }

    public function delete() {

	    $delete = M('Content')->where('id>0')->delete();
	    echo "删除了" . $delete . "条数据";
    }

    public function search() {

	    $search=I();
	    $searchd = $search['search'];
	    //p($searchd);

	    $search = M('Content')->where("`content` like '%$searchd%' or `title` like '%$searchd%'")->select();
	    //p($search);
	    $this->assign('search',$search);
	    $this->display();
    }
}
